﻿Public Class Deducciones 
    Public Sub Mostrar()
        If guardar.Enabled = False Then
            guardar.Enabled = True
            cancelar.Enabled = True
            agregar.Enabled = False
            modificar.Enabled = False
            eliminar.Enabled = False
            imprimir.Enabled = False
            PanelArriba.Enabled = True
            PanelAbajo.Enabled = False
        Else
            cancelar.Enabled = False
            guardar.Enabled = False
            agregar.Enabled = True
            Modificar.Enabled = True
            Eliminar.Enabled = True
            imprimir.Enabled = True
            PanelArriba.Enabled = False
            PanelAbajo.Enabled = True

        End If
    End Sub

    Private Sub EmpleadosdeduccionBindingNavigatorSaveItem_Click(sender As System.Object, e As System.EventArgs)
        Me.Validate()
        Me.EmpleadosdeduccionBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DbFireAndIceDataSet)

    End Sub


    Private Sub EmpleadosdeduccionBindingNavigatorSaveItem_Click_1(sender As System.Object, e As System.EventArgs) Handles EmpleadosdeduccionBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.EmpleadosdeduccionBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DbFireAndIceDataSet)

    End Sub

    Private Sub Deducciones_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.deduccionesconfig' table. You can move, or remove it, as needed.
        Me.DeduccionesconfigTableAdapter.Fill(Me.DbFireAndIceDataSet.deduccionesconfig)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.deduccionescategoria' table. You can move, or remove it, as needed.
        Me.DeduccionescategoriaTableAdapter.Fill(Me.DbFireAndIceDataSet.deduccionescategoria)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.empleados' table. You can move, or remove it, as needed.
        Me.EmpleadosTableAdapter.Fill(Me.DbFireAndIceDataSet.empleados)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.empleadosdeduccion' table. You can move, or remove it, as needed.
        Me.EmpleadosdeduccionTableAdapter.Fill(Me.DbFireAndIceDataSet.empleadosdeduccion)
        'IdempleadoLookUpEdit.Focus = True


    End Sub

   

    Private Sub agregar_Click(sender As System.Object, e As System.EventArgs) Handles agregar.Click
        Me.DeduccionesconfigTableAdapter.Fill(Me.DbFireAndIceDataSet.deduccionesconfig)
        BindingNavigatorAddNewItem.PerformClick()
        Mostrar()

    End Sub

    Private Sub modificar_Click(sender As System.Object, e As System.EventArgs) Handles modificar.Click
        Mostrar()
    End Sub

    Private Sub guardar_Click(sender As System.Object, e As System.EventArgs) Handles guardar.Click
        If IdempleadoLookUpEdit.Text.Length = 0 Then
            ErrorProvider1.SetError(IdempleadoLookUpEdit, "Debe ingresar un Empleado")
            Return
        Else
            If DescripcionTextBox.Text.Length = 0 Then
                ErrorProvider1.SetError(DescripcionTextBox, "Debe ingresar una descripción")
                Return
            Else
                If DateTimePicker1.Text = "" Then
                    ErrorProvider1.SetError(DateTimePicker1, "Debe ingresar una fecha")
                    Return
                Else

                    If IddeduccionescatLookUpEdit.Text.Length = 0 Then
                        ErrorProvider1.SetError(IddeduccionescatLookUpEdit, "Debe ingresar una categoría")
                        Return
                    Else
                        If MontoTextEdit.Text = "" Then
                            ErrorProvider1.SetError(MontoTextEdit, "Debe ingresar un monto")
                            Return
                        End If
                        ErrorProvider1.SetError(MontoTextEdit, Nothing)
                    End If
                End If
                ErrorProvider1.SetError(IddeduccionescatLookUpEdit, Nothing)

            End If
            ErrorProvider1.SetError(DateTimePicker1, Nothing)

        End If
        ErrorProvider1.SetError(DescripcionTextBox, Nothing)
        ErrorProvider1.SetError(IdempleadoLookUpEdit, Nothing)



        Try
            EmpleadosdeduccionBindingNavigatorSaveItem.PerformClick()
            Mostrar()
            AlertControl1.AppearanceCaption.ForeColor = Color.Green
            AlertControl1.Show(Me, "Advertencia", "Se guardó el resgistro satisfactoriamente")
            ' MsgBox(My.Resources.StringGlobal.msjGuardarExito)
        Catch ex As Exception
            AlertControl1.AppearanceCaption.ForeColor = Color.Red
            AlertControl1.Show(Me, "Error", "No se pudo guardar el registro")

        End Try


    End Sub

    Private Sub cancelar_Click(sender As System.Object, e As System.EventArgs) Handles cancelar.Click
        ErrorProvider1.SetError(DescripcionTextBox, Nothing)
        ErrorProvider1.SetError(IdempleadoLookUpEdit, Nothing)
        ErrorProvider1.SetError(IddeduccionescatLookUpEdit, Nothing)
        ErrorProvider1.SetError(DateTimePicker1, Nothing)
        ErrorProvider1.SetError(MontoTextEdit, Nothing)
        TextEdit1.Text = ""
        TextEdit2.Text = ""
        TextEdit3.Text = ""
        Mostrar()
        Try
            Me.EmpleadosdeduccionTableAdapter.Fill(Me.DbFireAndIceDataSet.empleadosdeduccion)

        Catch ex As Exception
            AlertControl1.AppearanceCaption.ForeColor = Color.Red
            AlertControl1.Show(Me, "Error", "No se puede cancelar")

        End Try
    End Sub

    Private Sub imprimir_Click(sender As System.Object, e As System.EventArgs) Handles imprimir.Click
        GridControl1.ShowPrintPreview()
    End Sub

    Private Sub eliminar_Click(sender As System.Object, e As System.EventArgs) Handles eliminar.Click
        Dim opcion As Integer
        opcion = MsgBox("¿Está seguro que desea eliminar el registro?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Eliminar registro")
        If opcion = vbYes Then
            Try
                EmpleadosdeduccionTableAdapter.DeleteDeduccionQuery(IdcorrelativoTextBox.Text)
                Me.EmpleadosdeduccionTableAdapter.Fill(Me.DbFireAndIceDataSet.empleadosdeduccion)
                AlertControl1.AppearanceCaption.ForeColor = Color.Green
                AlertControl1.Show(Me, "Advertencia", "Se eliminó satisfactoriamente")
            Catch ex As Exception
                AlertControl1.AppearanceCaption.ForeColor = Color.Red
                AlertControl1.Show(Me, "Error", "No se pudo eliminar el registro")
            End Try

        End If
    End Sub

   

   

    Private Sub MontoTextBox_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs)
        ''-_----------------------------------Validar solo números


        If Char.IsLetter(e.KeyChar) Then
            e.Handled = True
            AlertControl1.AppearanceCaption.ForeColor = Color.Red
            AlertControl1.Show(Me, "Advertencia", "Solo puede ingresar números")

            MontoTextEdit.Focus()

        ElseIf Char.IsSeparator(e.KeyChar) Then
            e.Handled = True
            AlertControl1.AppearanceCaption.ForeColor = Color.Red
            AlertControl1.Show(Me, "Advertencia", "No debe ingresar espacios")

            MontoTextEdit.Focus()

        Else
            e.Handled = False

        End If
    End Sub

    Private Sub IhssTextBox_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs)
        ''-_----------------------------------Validar solo números


        If Char.IsLetter(e.KeyChar) Then
            e.Handled = True
            MsgBox("Solo puede ingresar números", MsgBoxStyle.Information, "IHSS")
            IhssTextBox.Focus()

        ElseIf Char.IsSeparator(e.KeyChar) Then
            e.Handled = True
            MsgBox("No debe ingresar espacios", MsgBoxStyle.Information, "IHSS")
            IhssTextBox.Focus()

        Else
            e.Handled = False

        End If
    End Sub

    Private Sub FosoviTextBox_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs)
        ''-_----------------------------------Validar solo números


        If Char.IsLetter(e.KeyChar) Then
            e.Handled = True
            MsgBox("Solo puede ingresar números", MsgBoxStyle.Information, "FOSOVI")
            FosoviTextBox.Focus()

        ElseIf Char.IsSeparator(e.KeyChar) Then
            e.Handled = True
            MsgBox("No debe ingresar espacios", MsgBoxStyle.Information, "FOSOVI")
            FosoviTextBox.Focus()

        Else
            e.Handled = False

        End If
    End Sub

   
  
    Private Sub RapTextBox_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs)
        ''-_----------------------------------Validar solo números


        If Char.IsLetter(e.KeyChar) Then
            e.Handled = True
            AlertControl1.AppearanceCaption.ForeColor = Color.Red
            AlertControl1.Show(Me, "Advertencia", "Solo puede ingresar números")
            RapTextBox.Focus()

        ElseIf Char.IsSeparator(e.KeyChar) Then
            e.Handled = True
            AlertControl1.AppearanceCaption.ForeColor = Color.Red
            AlertControl1.Show(Me, "Advertencia", "Solo puede ingresar números")
            RapTextBox.Focus()

        Else
            e.Handled = False

        End If
    End Sub

    'Private Sub IdempleadoLookUpEdit_EditValueChanged(sender As System.Object, e As System.EventArgs)
    '    'primero condicionamos que el lookup no esté nulo. porque cuando el form carga no se ha n llenado los tableadapters tonces:
    '    If Not IsDBNull(IdempleadoLookUpEdit) Then  'si no es nulo el lookupedit
    '        TextEdit1.EditValue = IdempleadoLookUpEdit.GetColumnValue("idcargo")
    '        TextEdit2.EditValue = IdempleadoLookUpEdit.GetColumnValue("apellido")
    '        TextEdit3.EditValue = IdempleadoLookUpEdit.GetColumnValue("nombre")
    '        ImageEdit1.EditValue = IdempleadoLookUpEdit.GetColumnValue("fotografia")
    '        'vamos a ver
    '    End If
    'End Sub

    Private Sub MontoTextEdit_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles MontoTextEdit.KeyPress
        'If Char.IsLetter(e.KeyChar) Then
        '    e.Handled = True
        '    MsgBox("Solo puede ingresar números", MsgBoxStyle.Information, "Monto")
        '    MontoTextEdit.Focus()

        'ElseIf Char.IsSeparator(e.KeyChar) Then
        '    e.Handled = True
        '    MsgBox("No debe ingresar espacios", MsgBoxStyle.Information, "Monto")
        '    MontoTextEdit.Focus()

        'Else
        '    e.Handled = False

        'End If

        If Char.IsLetter(e.KeyChar) Then
            e.Handled = True
            AlertControl1.AppearanceCaption.ForeColor = Color.Red
            AlertControl1.Show(Me, "Advertencia", "Solo puede ingresar números")

            MontoTextEdit.Focus()

        Else


            If Char.IsSeparator(e.KeyChar) Then
                e.Handled = True
                AlertControl1.AppearanceCaption.ForeColor = Color.Red
                AlertControl1.Show(Me, "Advertencia", "No debe ingresar espacios")

                MontoTextEdit.Focus()

            Else
                e.Handled = False

            End If
        End If
    End Sub

    Private Sub IdempleadoLookUpEdit_EditValueChanged(sender As System.Object, e As System.EventArgs) Handles IdempleadoLookUpEdit.EditValueChanged
        If Not IsDBNull(IdempleadoLookUpEdit) Then  'si no es nulo el lookupedit
            TextEdit1.EditValue = IdempleadoLookUpEdit.GetColumnValue("idcargo")
            TextEdit2.EditValue = IdempleadoLookUpEdit.GetColumnValue("apellido")
            TextEdit3.EditValue = IdempleadoLookUpEdit.GetColumnValue("nombre")
            ImageEdit1.EditValue = IdempleadoLookUpEdit.GetColumnValue("fotografia")
        End If
    End Sub

  
End Class